home *** CD-ROM | disk | FTP | other *** search
- MikDLL by MikMak / HaRDCoDE '95
- ===============================
-
- MikDLL is a set of routines which enable you to create & use your own
- dynamically loadable libraries for DOS, without having to use any assembly.
-
- Now I can hear you thinking 'do I need this shit?', well most of you
- probably don't need it. But suppose you're writing a modplayer (hehe) and
- you have to support lots of different soundcards.. are you just going to
- statically link all those different drivers to your .exe and create one HUGE
- program which eats up a lot of memory?? NO! Use MikDLL to create separate
- MDLL .EXE files for each driver; when your modplayer starts, simply load and
- link the driver you need at that time.
-
-
- Advantages:
-
- - Smaller main .EXE
-
- - Uses less diskspace (the unused drivers can be deleted)
-
- - It's easier to add new functionality/support to your program.. you
- only have to make a new MDLL and there's no need to rebuild the main
- program.
-
- - You'll learn how to program in a more object-oriented fashion.
-
- - It's elegant (you eediot!).
-
-
- Before I go on I have to give some credit to Otto Chrons who invented (?)
- this kind of DLL (he uses it for DMP) (tho he didn't tell me about that dos
- function to load an executable ;)
-
-
- How does it work?
- =================
-
- When you load a MDLL using the function MDLL_Bind() it does the following:
-
- - It reserves enough memory for the MDLL
-
- - It uses dos function 0x4b03 (EXEC-load overlay) to actually load &
- relocate the .exe into the reserved memory.
-
- - It searches the overlay memory for a certain structure (TAG) by which
- it can access the MDLL entry function.
-
- - It executes the entry function so the MDLL can import or export
- certain functions or data.
-
- Next, the main program can import routines/data that was previously
- exported by the MDLL entry function.
-
-
- Limitations
- ===========
-
- - You can't use a library function of a MDLL if it needs some kind of
- initialisation in the startup-code of an .EXE, like printf(), malloc(),
- getenv().. if you have to use them anyway, use the parents functions by
- importing them into your MDLL.
-
- - You'd better use the same memory model in both MDLL and parent programs,
- or else the parameter passing will fail.
-
- - Borlands Tiny, Small, Medium and Compact libraries assume DS=SS which
- isn't the case with MDLLs.. this will affect some library functions like
- sprintf. My advice: use Large model only.
-
- - Both the parent & MDLL programs have their own data segment. When calling
- a MDLL function from the parent and vice versa you have to make sure that
- each function uses the correct data segment by putting '_loadds' or 'huge'
- in front of every exported function.
-
- - Do NOT pklite or lzexe the MDLL executable. The unpacking code won't be
- executed so the MDLL loader might execute garbage, resulting in a crash.
-
-
- Examples
- ========
-
- I've included an example on how to use the MDLL functions. There's a program
- called PARENT.EXE that'll dynamically load CHILD.EXE and use one of it's
- functions and CHILD.EXE uses one of the parent functions. Neat huh?
-
-
- Future
- ======
-
- All MDLL executables have 4k of startup code which isn't needed.. by using
- your own startup code (replacing c0x.asm) you could reduce the size of the
- MDLLs. You could also use this to place the entry TAG on a fixed location
- within the .exe so the MDLL loader doesn't have to search for it.
-
-
- Feedback
- ========
-
- Send your questions, comments, bugreports or money to:
-
- Email: mikmak@stack.urc.tue.nl
-
- Smail: Jean-Paul Mikkers
- Godartstr. 16
- 5932 AX Tegelen
- the Netherlands
-
-
- Disclaimer
- ==========
-
- This is public domain. Use at your own risk. Don't try to understand it.
-
-
- ----------------------------------------------------------------------------
-
-
-
- void huge MDLL_Export(char *name,void *obj)
- ===========================================
-
- Adds an object (function or a datablock) to the exports-pool so a MDLL can
- use that object in the future.
-
- Input:
-
- char *name : The ASCIIZ name of the object to be exported, by
- which it will be registered in the exports-pool.
-
- void *obj : The address of the object to be exported.
-
-
- Returns: -
-
-
-
- void * huge MDLL_Import(char *name)
- ===================================
-
- Finds the address of an object by reference of it's name. This routine is
- used by a DLL to access external functions/data.
-
- Input:
-
- char *name : The ASCIIZ name of the object to be imported.
-
-
- Returns:
-
- The address of the object.
-
- Note:
- When the object can't be found, this function will report the failure and
- exit the program.
-
-
-
- int MDLL_Bind(MDLL *mp,char *name)
- ==================================
-
- Input:
-
- MDLL *mp : pointer to an uninitialised MDLL structure which is
- used to store information of the MDLL.
-
- char *name : The name of the executable which has to be loaded
- as an MDLL.
-
-
- Returns:
-
- 1 - No problem
- 0 - An error occured. use MDLL_Error() to find out what went wrong.
-
-
-
- void MDLL_Unbind(MDLL *mp)
- ==========================
-
- Frees the memory taken up by the MDLL and removes the exports from this MDLL
- from the exports-pool. !! Only use this function when MDLL_Bind was
- succesful !!
-
- Input:
-
- MDLL *mp : pointer to a MDLL structure (which was filled by
- MDLL_Bind() )
-
- Returns:
-
- -
-
-
-
- char *MDLL_Error(void)
- ======================
-
- Returns an error-string which describes what went wrong loading a MDLL.
-
-
- Input:
-
- -
-
- Output:
-
- the error description string
-
-
- ----------------------------------------------------------------------------
-